package com.szpx.controller.twoGroup;

import com.szpx.dto.Result;
import com.szpx.entity.Goods;
import com.szpx.service.GoodsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Wangtx
 * @version 1.0.0
 * @title GoodsController
 * @create 2024/4/6 22:36
 * @description
 */
@RestController
@RequestMapping("/goods")
@CrossOrigin
public class GoodsController {
    @Resource
    private GoodsService goodsService;

    @GetMapping(value = "/findAllGoodsPage")
    public Result findAllGoodsPage(@RequestParam(value = "pageNo") Integer pageNo,@RequestParam(value = "pageSize") Integer pageSize, Integer id){
        System.out.println("浏览");
        return Result.ok(goodsService.findAllGoodsPage(pageNo,pageSize,id));
    }//浏览

    @PostMapping("/addGoods")
    public Result addGoods(@RequestBody Goods goods){
        System.out.println("生成");
        goodsService.addGoods(goods);
        return Result.ok();
    }//生成

    @PutMapping("/updateGoods")
    public Result updateGoods(@RequestBody Goods goods){
        System.out.println("修改");
        goodsService.updateGoods(goods);
        return  Result.ok();
    }//修改

    @GetMapping(value = "/deleteGoodsByGoodsId")
    public Result deleteGoodsByGoodsId(Integer id){
        System.out.println("删除");
        goodsService.deleteGoodsByGoodsId(id);
        return Result.ok();
    }//单个删除

    @PostMapping(value = "/deleteAllSelectGoods")
    public Result deleteAllSelectGoods(@RequestBody List<Integer> goodsIds){
        goodsService.deleteAllSelectGoods(goodsIds);
        return Result.ok();
    }

    @GetMapping(value = "/allFreightPrice/{id}")
    public Integer allFreightPrice(@PathVariable(value = "id")Integer id){
        System.out.println("计算");
        Integer price=goodsService.allFreightPrice(id);
        return price;
    }//计算
    @GetMapping(value = "/getGoodsList")
    public Result getGoodsList(){
        return Result.ok(goodsService.getGoodsList());
    }


}
